#!/bin/bash

config=/etc/goto.conf
hostname=$1
loginssh=/etc/goto.conf.d/loginssh

if [ $# != 1 ];then
    echo "Usage: $0 hostname"
    exit 1
fi

login_to_server()
{
    case $2 in
        "ssh")
           $loginssh $2 $3 $4 $5 $6
        ;;
        *)
           echo "Usage: $2 not support"
           exit 3
        ;;
    esac
}

loginstr=`grep "^$hostname " $config | sed -n 1p`
if [ -z "$loginstr" ];then
    echo "unknown $hostname in $config"
    exit 2
fi

login_to_server $loginstr
exit $?
